package com.asset.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.asset.common.annotation.Log;
import com.asset.common.core.controller.BaseController;

import com.asset.common.core.domain.R;
import com.asset.common.enums.BusinessType;
import com.asset.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import com.asset.manage.domain.Company;
import com.asset.manage.service.ICompanyService;


/**
 * 组织架构Controller
 *
 * @author mobin
 * @date 2024-08-24
 */
@Api(tags = "组织架构")
@RestController
@RequestMapping("/manage/company")
public class CompanyController extends BaseController {
    @Autowired
    private ICompanyService companyService;

    /**
     * 查询组织架构列表
     */
    @ApiOperation("查询组织架构列表")
    @PreAuthorize("@ss.hasPermi('manage:company:list')")
    @GetMapping("/list")
    public R<List<Company>> list(Company company) {
        List<Company> list = companyService.selectCompanyList(company);
        return R.ok(list);
    }

    /**
     * 导出组织架构列表
     */
    @ApiOperation("导出组织架构列表")
    @PreAuthorize("@ss.hasPermi('manage:company:export')")
    @Log(title = "组织架构", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Company company) {
        List<Company> list = companyService.selectCompanyList(company);
        ExcelUtil<Company> util = new ExcelUtil<Company>(Company.class);
        util.exportExcel(response, list, "组织架构数据");
    }

    /**
     * 获取组织架构详细信息
     */
    @ApiOperation("获取组织架构详细信息")
    @PreAuthorize("@ss.hasPermi('manage:company:query')")
    @GetMapping(value = "/{id}")
    public R<Object> getInfo(@PathVariable("id") Long id) {
        return R.ok(companyService.selectCompanyById(id));
    }

    /**
     * 新增组织架构
     */
    @ApiOperation("新增组织架构")
    @PreAuthorize("@ss.hasPermi('manage:company:add')")
    @Log(title = "组织架构", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Object> add(@RequestBody Company company) {
        return R.ok(companyService.insertCompany(company));
    }

    /**
     * 修改组织架构
     */
    @ApiOperation("修改组织架构")
    @PreAuthorize("@ss.hasPermi('manage:company:edit')")
    @Log(title = "组织架构", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Object> edit(@RequestBody Company company) {
        return R.ok(companyService.updateCompany(company));
    }

    /**
     * 删除组织架构
     */
    @ApiOperation("删除组织架构")
    @PreAuthorize("@ss.hasPermi('manage:company:remove')")
    @Log(title = "组织架构", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Object> remove(@PathVariable Long[] ids) {
        return R.ok(companyService.deleteCompanyByIds(ids));
    }
}
